#! /usr/bin/env python

import os
import sys

if os.geteuid() != 0:
	print 'must be run under root'
	sys.exit()

curdir=sys.path[0]

f=open("%s/ips.txt"%curdir)
g=f.readlines()
f.close()

a=[]
for i in g:
	k=i.strip(' ').split()	
	a.append(k[0])

a=list(set(a))

n_ip=0
for ip in a:
	if not os.path.exists('%s/data/%s'%(curdir,ip)):
		n_ip=n_ip+1

try:
	count=0
	for ip in a:
			if not os.path.exists('%s/data/%s'%(curdir,ip)):
				count=count+1			
				print "Tracerouting ip #%4d of %d: %s" % (count, n_ip, ip) 
				os.system('/usr/bin/traceroute -m 20 -q 3 -w 1 -n %s > %s/data/%s' % (ip,curdir,ip))
except KeyboardInterrupt :
	raise
except:
	pass	

